﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Commander.Core.AI {
	public class EncodingGenerator {

    static string[] rules = new string[3] {"AvoidCodeDuplicatedInSameClassRule","AvoidSpeculativeGeneralityRule","AvoidMessageChainsRule" };

		public static Population GenerateInitialPopulation(Encoding ancestor, int populationSize) {
      Population pop = new Population();
      while (pop.Count < populationSize) {

        pop.Add(MixList(ancestor.Clone()));
      }
			return pop;
		}

    public static Encoding MixList(Encoding input) {
      Encoding randomList = new Encoding();
      Encoding inputList = input.Clone();
      //inputList.InitialDefects = input.InitialDefects;
      randomList.InitialDefects = inputList.InitialDefects;
      randomList.FilePath = input.FilePath;
      Random r = new Random();
      int randomIndex = 0;
      while (inputList.Count > 0) {
        randomIndex = r.Next(0, inputList.Count); //Choose a random object in the list
        randomList.Add(inputList[randomIndex]); //add it to the new, random list
        inputList.RemoveAt(randomIndex); //remove to avoid duplicates
      }
      return randomList; //return the new random list
    }

	}
}
